const express = require('express')
let app = express()
app.listen(3000, () => {
    console.log('3000ok');
})

// 引入模块
const mysql = require("mysql");
// 创建连接
let con = mysql.createConnection({
    host: "localhost",
    port: 3306,
    user: "root",
    password: "root",
    database: "user"
})

con.connect()



function query(sql) {
    return new Promise((resolve, reject) => {
        con.query(sql, (err, results) => {
            resolve([err, results])
        })
    })

    // return p
}




app.get("/userinfo", (req, res) => {


    let sql = `select *  from user`
    let sql1 = `select *  from user where id=2`



    async function getuser() {
        let [err, results] = await query(sql)
        console.log([err, results]);

        let [err1, results1] = await query(sql1);
        console.log([err1, results1]);

    }
    getuser()


    res.send("Ok")




})